package com.example.myproject;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

public final class EMF {
	private static final EntityManagerFactory emfInstance = Persistence
			.createEntityManagerFactory("transactions-optional-emf");

	private static EntityManager EM;
	
	private EMF() {
	}

	public static EntityManagerFactory get() {
		return emfInstance;
	}
	
	public static EntityManager getEM() {
    	if (EM == null) {
    		EM = get().createEntityManager();
    	}
    	if (!EM.isOpen()) {
    		EM = get().createEntityManager();
    	}
    	return EM;
    }
}
